<h2>Events<?php addPost('event'); ?></h2>
<?php 
if($_POST){
//var_dump($_POST);
	$d = $_POST['d'];
	$m = $_POST['m'];
	$y = $_POST['y'];
	if($d < 10){
		$d = '0'.$d;
	}
	if($m < 10){
		$m = '0'.$m;
	}
	$datetosearch = " and startdate like '".$y."-".$m."-".$d."'";
}else{
	$datetosearch = '';
}
?>
<div class="posts" id="posts">
<?php 
$siteid = $site['id'];
$postsqry = dbSelect('posts',array("site_id=$siteid","parent_id=0","type_id=2 $datetosearch"),"ORDER BY startdate DESC,starttime DESC");
$eventcnt = 0;
if(mysql_numrows($postsqry) > 0){ 
$dateheader = 0;
	while($posts = mysql_fetch_array($postsqry)){
		$userid = $posts['author_id'];
		$author = mysql_fetch_array(dbSelect('users',array("id=$userid")));
		$authorname = $author['firstname'].' '.$author['lastname'];
		$nicetime = nicetime($posts['publishdate']);

	if($laststartdate!=$posts['startdate']){
		$dateheader=0;
	}
	if($dateheader==0){ 
		
		echo '<div class="event_date" style="font-size: 16pt; font-weight: bold; color: #808080;">'.date('F j, Y',dateformat($posts['startdate'])).'</div>';
		$dateheader++;
		$laststartdate = $posts['startdate'];
	} 
?>
	<div class="post" style="padding-left: 10px;">
		<div class="post_title"><?php echo urldecode($posts['title']); ?></div>
		<span class="event_times"><?php echo $posts['starttime']; ?><?php if($posts['endtime']!=""){echo ' - '.$posts['endtime'];} ?></span>
		<span class="event_details" style="font-size: small; font-weight: normal; color: #303030;">
					<?php if($posts['event_type'] > 0){
					$eventtypeid = $posts['event_type'];
					$eventtype_qry = dbSelect('ddl_event_type',array("id=$eventtypeid"));
					if(mysql_numrows($eventtype_qry) > 0){
						$eventtypearr = mysql_fetch_array($eventtype_qry);
						$event_type = $eventtypearr['type'];
					}
					echo $event_type;}else{echo 'an event';} ?> 
					<?php if($posts['event_agegroup'] > 0){
					$eventagegroupid = $posts['event_agegroup'];
					$eventagegroup_qry = dbSelect('ddl_agegroup',array("id=$eventagegroupid"));
					if(mysql_numrows($eventagegroup_qry) > 0){
						$eventagegrouparr = mysql_fetch_array($eventagegroup_qry);
						$event_agegroup = $eventagegrouparr['agegroup'];
					}
					echo ' for '.$event_agegroup;}else{echo ' for all ages';} ?>
					<?php if($posts['event_isonsite']==1){ 
					echo 'at '.$site['name'];
						echo '&nbsp;<a title="via Google" class="fakelinktiny" href="http://maps.google.com/?q='.urlencode($site['address']).' '.urlencode($site['address2']).' '.urlencode($site['city']).', '.urlencode($site['state']).' '.urlencode($site['zip']).'" target="_blank">map</a>'; 
					}else{
						echo 'at '.$posts['event_addr'].' '.$posts['event_addr2'].' '.$posts['event_city'].', '.$posts['event_state'].' '.$posts['event_zip'];
						echo '&nbsp;<a title="via Google"  class="fakelinktiny" href="http://maps.google.com/?q='.urlencode($posts['event_addr']).' '.urlencode($posts['event_addr2']).' '.urlencode($posts['event_city']).', '.urlencode($posts['event_state']).' '.urlencode($posts['event_zip']).'" target="_blank">map</a>'; 
					} ?>
					<br />
					<span class="fakelinktiny" onclick="$('#moreinfo_<?php echo $eventcnt; ?>').toggle(); $('#rsvp_<?php echo $eventcnt; ?>').hide(); $('#providecare_<?php echo $eventcnt; ?>').hide();">more info</span>
					&nbsp;<span class="fakelinktiny" onclick="$('#rsvp_<?php echo $eventcnt; ?>').toggle(); $('#moreinfo_<?php echo $eventcnt; ?>').hide(); $('#providecare_<?php echo $eventcnt; ?>').hide();">rsvp</span>
					<?php if($isadmin==1 || $ischildcarecoord==1){ ?>
						&nbsp;<span class="fakelinktiny" onclick="$('#providecare_<?php echo $eventcnt; ?>').toggle(); $('#moreinfo_<?php echo $eventcnt; ?>').hide(); $('#rsvp_<?php echo $eventcnt; ?>').hide();">provide care</span>
					<?php } ?>
				<div class="moreinfo" id="moreinfo_<?php echo $eventcnt; ?>" style="display: none;">
					<br />
					<div class="moreinfo_outer">
					<h3>More Information</h3>
					<!---event cost/per--->
					<div class="moreinfo_inner">
						<span><?php echo '$'.$posts['event_cost']; ?></span>
						<?php 
						if($posts['event_per'] > 0){
							$eventperid = $posts['event_per'];
							$eventper_qry = dbSelect('ddl_event_per',array("id=$eventperid"));
							if(mysql_numrows($eventper_qry) > 0){
								$eventperarr = mysql_fetch_array($eventper_qry);
								$event_per = $eventperarr['per'];
							}
							echo $event_per;
						}else{
							echo 'per person';
						} 
						?>
						<!---/event cost/per--->
						<!---event child cost/per--->
							<?php if($posts['event_ischildcare']){echo '<br /><span class="">$'.$posts['childcare_cost'].'</span>'; ?>
							<?php if($posts['cc_per'] > 0){
							$eventccperid = $posts['cc_per'];
							$eventccper_qry = dbSelect('ddl_cc_per',array("id=$eventccperid"));
							if(mysql_numrows($eventccper_qry) > 0){
								$eventccperarr = mysql_fetch_array($eventccper_qry);
								$event_ccper = $eventccperarr['cc_per'];
							}
							echo $event_ccper;}else{echo 'per child';}
							echo '<span class="green" style="font-weight: bold;"> in event</span>';
							} ?>
						<!---/event child cost/per--->
						<!---childcare cost/per--->
						<?php if($posts['event_ischildcare']){echo '<br /><span class="">$'.$posts['childcare_cost'].'</span>'; ?>
						<?php if($posts['cc_per'] > 0){
						$eventccperid = $posts['cc_per'];
						$eventccper_qry = dbSelect('ddl_cc_per',array("id=$eventccperid"));
						if(mysql_numrows($eventccper_qry) > 0){
							$eventccperarr = mysql_fetch_array($eventccper_qry);
							$event_ccper = $eventccperarr['cc_per'];
						}
						echo $event_ccper;}else{echo 'per child';}
						echo '<span class="green" style="font-weight: bold;"> for childcare</span>';
						}else{echo '<span class="red">No childcare available.</span>';} ?><br />
						<!---/childcare cost/per--->
						<!---event desc--->
						<?php echo '<br /><strong>Description:</strong> '.$posts['post']; ?>
						<br />would you like to <span class="fakelinktiny" onclick="$('#moreinfo_<?php echo $eventcnt; ?>').toggle(); $('#rsvp_<?php echo $eventcnt; ?>').toggle();">rsvp for this?</span>
						<!---/event desc--->
						</div>
					</div>
					</div>
				<div class="moreinfo" id="rsvp_<?php echo $eventcnt; ?>" style="display: none;">
					<br /> 
					<div class="moreinfo_outer">
						<h3>RSVP</h3>
						this is an RSVP...
					</div>
				</div>
				<div class="providecare" id="providecare_<?php echo $eventcnt; ?>" style="display: none;">
					<br /><br />
					<div class="moreinfo">
						<h3>Provide Care</h3>
						this is providing care...
					</div>
				</div>
				<br />
				<?php editDel($posts['id'],$posts['author_id'],'event'); ?>
	</span>
		<!---where comments would go--->
	</div><!--/post-->
<?php
	$eventcnt++;
	} /* /while posts */
}else{echo 'No events for this day.';} /* /if posts */
?>
</div><!--/posts-->